<?php
class users_AclController extends Zend_Controller_Action
{
	public function init()
    {
        /* Initialize action controller here */
    	defined('BASE_URL')	|| define('BASE_URL', Zend_Controller_Front::getInstance()->getBaseUrl());
    }

    public function indexAction()
    {
         $db = new users_Model_DbTable_DbAcl();
         $aclQuery = "SELECT `acl_id`,`module`,`controller`,`action`,`status` FROM tbwu_acl_acl";
         $rows = $db->getAclInfo($aclQuery);
         $this->view->frmacl = $rows;
    	if($this->getRequest()->isPost()){
    		$data = $this->getRequest()->getPost();
    		if(isset($data['status'])){
    			$ids = $data['status'];
    			$db->updateUnStatus($ids);
    			$this->_redirect("/users/acl");   			
    		}elseif (isset($data['unstatus'])){
    			$ids = $data['unstatus'];
    			$db->updateStatus($ids);
    			$this->_redirect("/users/acl");
    		}   		
    		$id = $data['checkBox']; 
    		if(isset($data['update'])&& $id !=""){   			
    			$this->_redirect("/users/acl/edit/id/".$id);
    		}elseif(isset($data['delete'])&& $id !=""){
    			$db->deleteAcl($id);
		    	Application_Form_FrmMessage::message("កាលុបប្រភេទអ្នកប្រើប្រាស់បានជោគជ័យ");
		    	Application_Form_FrmMessage::redirectUrl('/users/acl');
    		}else { $this->_redirect("/users/acl");}
    		
    	}
    }
	public function addAction()
		{
			$form = new users_Form_FrmAcl();
			
			$this->view->formacl=$form->frmacl();			
 			if($this->getRequest()->isPost())
 			{
 				$db = new users_Model_DbTable_DbAcl();
 				$data = $this->getRequest()->getPost();
 				if(isset($data['save'])){
 					$db->insertAcl($data);
 					Application_Form_FrmMessage::message("កាបញ្ចូលប្រភេទអ្នកប្រើប្រាស់បានជោគជ័យ");
 				}
 				if(isset($data['save_close'])){
 					$db->insertAcl($data);
 					Application_Form_FrmMessage::message("កាបញ្ចូលប្រភេទអ្នកប្រើប្រាស់បានជោគជ័យ");
 					Application_Form_FrmMessage::redirectUrl('/users/acl');
 				}
 			}
		}
    public function editAction()
    {	
    	$acl_id = $this->getRequest()->getParam('id');		
    	$db = new Application_Model_DbTable_DbGlobal();
    	$sql = 'SELECT * FROM `tbwu_acl_acl` WHERE acl_id='.$acl_id;
        $rows = $db->getGlobalDbRow($sql);
        $form = new users_Form_FrmAcl();
    	$this->view->formacl = $form->frmacl($rows);
    }
    public function deleteAction(){
    	$id = $this->getRequest()->getParam('id');
    	$db = new users_Model_DbTable_DbAcl();
    	$db->deleteAcl($id);
    	Application_Form_FrmMessage::message("កាលុបប្រភេទអ្នកប្រើប្រាស់បានជោគជ័យ");
    	$this->_redirect('/users/acl');
    }
    public function getfillteraddAction(){
    	if($this->getRequest()->IsPost()){
    		$data = $this->getRequest()->getPost();
    		$username = $data['username'];
    		$sql= "SELECT username FROM tbwu_acl_user WHERE username = '$username'";
    		$db = new Application_Model_DbTable_DbGlobal();
    		$row = $db->getGlobalDbRow($sql);
    		echo Zend_Json::encode($row);
    		exit();
    	}
    }
}